<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
	<title>
理解Git的暂存区 | 
穷折腾</title>
	<link rel="stylesheet" href="/static/css/style.css" />
	<link rel="stylesheet" href="/static/css/pygments.css" />
	<link rel="alternate" type="application/rss+xml" title="RSS" href="http://zqqf16.info/rss.xml" />
	
</head>
<body>
    <div id="container">
      <div id="main" role="main">
        <header>
		<h1>
理解Git的暂存区
</h1>
		</header>

     <nav>
		<span><a title="home page" class="" href="/">home</a></span>
        <span><a href="/pages/about.html" title="关于">关于</a></span>
     </nav>

     <article class="content">
        <section class="post">
            
		<p>虽然用了好几个月的Git，今天才了解了“换存区”这个东西，惭愧啊。。。</p>
<p>在公司用的是CVS，因此用<code>git add</code>的时候就以为和<code>cvs add</code>的作用是一样的，把新文件加到代码库。后来学了一招<code>git commit -a</code>，还以为-a就是--all的意思。稀里糊涂地用到现在。。。</p>
<p>Git中的暂存区类似于任务列表，当对工作区的文件做了修改之后，执行</p>
<div class="codehilite"><pre>git add filename
</pre></div>


<p>就会把修改的文件加到这个任务列表中，当执行</p>
<div class="codehilite"><pre>git commit
</pre></div>


<p>的时候，暂存区中的改动就会提交到版本库中，而在“git add”之后所做的改动就不会被提交。</p>
<p>命令</p>
<div class="codehilite"><pre>git checkout filename
</pre></div>


<p>是用暂存区中的文件来替换工作区中的文件。</p>
<p>命令</p>
<div class="codehilite"><pre>git checkout HEAD
</pre></div>


<p>是用HEAD指向的版本库中的文件来替换暂存区和工作区的文件。</p>
<p>好了，先这么多了。通过这件事总结出一个道理：经验有时候会形成思维定势。</p>
	</section>
	<section class="meta">
		<span class="tags">Tagged by 
			<a href="/tags/Git.html">Git</a>
			<a href="/tags/暂存区.html">暂存区</a>
		</span>

		<span class="time">&nbsp;<time datetime="2013-06-05">2013-06-05</time></span>
	</section>
	<div id="disqus_thread"></div>
<script type="text/javascript">
    var disqus_shortname = 'zqqf16';
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

<hr/>


        </section>
     </article>
	 <div id="copy">&copy; Powered by <a href="https://github.com/zqqf16/zqqf16.github.com" title="Peanut">Peanut</a> | Themed by <a href="http://lhzhang.com" title="sext ii">sext ii</a></div>
      </div>
    </div> <!--! end of #container -->
    <script type="text/javascript">
        var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
        document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F0100dcff30150b1fe336a8b5d0d50684' type='text/javascript'%3E%3C/script%3E"));
    </script>
  </body>
</html>
